package com.zjbti.commonview;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
//获取界面中的控件
    private Button button2,button3,button4;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        //获取按钮
        button2 = findViewById(R.id.button2);
        button3 = findViewById(R.id.button3);
        button4 = findViewById(R.id.button4);

        //setOnClickListener 设置事件监听器
        //button4.setOnClickListener 给button4设置事件监听器
        //MainActivity就是监听器，因为有监听能力
        //MainActivity的监听能力是从implements接口View.OnClickListener获取来的监听能力
        //View.OnClickListener如何监听
        //通过实现public void OnClick（View View）抽象方法
        //设置时间监听器
        button4.setOnClickListener(this);

        //设置时间监听器 匿名内部类 ：lambda表达式
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //实现效果
                button3.setText("你已点击按钮3");
            }
        });
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;

        });
    }

    public void click(View view) {
        //实现效果
        button2.setText("你已经点击按钮2");
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.button4) {
            button4.setText("你已点击按钮4");
        }
    }


}